package com.oa.util;

import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.oa.entity.Power;
import com.oa.service.PowerService;

public class InitListener implements ServletContextListener {

	// 监听 启动初始化数据
	public void contextInitialized(ServletContextEvent sce) {
		ApplicationContext ac = WebApplicationContextUtils
				.getWebApplicationContext(sce.getServletContext());
		PowerService powerService = (PowerService) ac
				.getBean("powerService");

		List<Power> topPowerService = powerService.findTopList();
		sce.getServletContext().setAttribute("topPowerList",
				topPowerService);
		System.out.println("------------ 已经准备 左侧菜单栏的 数据放到 整个应用中------------");
	}

	// 监听 销毁数据
	public void contextDestroyed(ServletContextEvent sce) {

	}

}
